#region Using directives
using System;
using System.Text;
using System.Data;
using System.Collections;
using WP.MF.DataEntity;
using WP.MF.DataAccess;
using WP.MF.BusinessRule;
using WP.DB;
using WP.Commons;
#endregion

namespace WP.MF.BusinessLogical 
{
    public class MSwitchBLL : IBusinessLogical
    {
        MSwitchDAL mSwitchDAL = new MSwitchDAL();
        public MSwitchBLL()
		{
		}
        #region ***For implement interface
        #region Select Record by RECID OverLoad +1
        public MSwitchDEL SelectDataByRecID(DBAccess dBAccess, string strRecId)
        {
            MSwitchDEL mSwitchDEL = new MSwitchDEL();
            DataFunctions.SelectByRecID(dBAccess, mSwitchDEL, mSwitchDAL.Fields, strRecId);
            return mSwitchDEL;
        }
        public IDataEntity SelectDataByRecID(string strRecId)
        {
            DBAccess dBAccess = new DBAccess(false, false);
            try
            {
                MSwitchDEL mSwitchDEL = SelectDataByRecID(dBAccess, strRecId);
                return mSwitchDEL as IDataEntity;
            }
            catch (Exception e)
            {
                ExceptionManager.ProcessException(e);
                return null;
            }
            finally
            {
                dBAccess.CloseCon();
            }
        }
        #endregion
        #region Insert MSwitch
        public bool Insert(DBAccess dBAccess, MSwitchDEL mSwitchDEL)
        {
            bool bFlag = true;
            MSwitchBRL mSwitchBRL = new MSwitchBRL();
            if (mSwitchBRL.InsertValid(dBAccess, mSwitchDEL))
            {
                mSwitchDAL.InsertMSwitch(dBAccess, mSwitchDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        public bool Insert(IDataEntity iMSwitchDEL)
        {
            bool bReturn = true;
            DBAccess dBAccess = null;
            MSwitchDEL mSwitchDEL = iMSwitchDEL as MSwitchDEL;
            dBAccess = new DBAccess(false, true);
            try
            {
                bReturn = Insert(dBAccess, mSwitchDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTran();
                bReturn = false;
                ExceptionManager.ProcessException(e);
            }
            return bReturn;
        }
        #endregion
        #region Update MSwitch
        public bool Update(DBAccess dBAccess, MSwitchDEL mSwitchDEL)
        {
            bool bFlag = true;
            MSwitchBRL mSwitchBRL = new MSwitchBRL();
            if (mSwitchBRL.UpdateValid(dBAccess, mSwitchDEL))
            {
                mSwitchDAL.UpdateMSwitch(dBAccess, mSwitchDEL);
            }
            else
            {
                bFlag = false;
            }
            return bFlag;
        }
        public bool Update(IDataEntity iMSwitchDEL)
        {
            bool bReturn = true;
            MSwitchDEL mSwitchDEL = iMSwitchDEL as MSwitchDEL;
            DBAccess dBAccess = new DBAccess(false, true);
            try
            {
                bReturn = Update(dBAccess, mSwitchDEL);
                if (bReturn)
                {
                    dBAccess.CommitTranAndCloseCon();
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTran();
                ExceptionManager.ProcessException(e);
                bReturn = false;
            }
            return bReturn;
        }
        #endregion
        #region Delete MSwitch
        public bool Delete(string strRecId, byte[] btOldRecStamp)
        {
            MSwitchBRL mSwitchBRL = new MSwitchBRL();
            DBAccess dBAccess = new DBAccess(false, true);
            try
            {
                if (mSwitchBRL.DeleteValid(dBAccess, strRecId, btOldRecStamp))
                {
                    mSwitchDAL.DeleteMSwitch(dBAccess, int.Parse(strRecId));
                    dBAccess.CommitTranAndCloseCon();
                    return true;
                }
                else
                {
                    dBAccess.RollbackTranAndClose();
                    if (SysVar.ErrorMessage.Count > 0)
                    {
                        MsgBoxEx.Show(SysVar.ErrorMessage, SysVar.WarnTitle);
                    }
                    return false;
                }
            }
            catch (Exception e)
            {
                dBAccess.RollbackTranAndClose();
                ExceptionManager.ProcessException(e);
                return false;
            }
        }
        #endregion
        #endregion***
    }
}
